#include <stdio.h>
#include <string.h>

struct Student {
    char name[50];
    int score;
};

void bubbleSort(struct Student arr[], int n) {
    for (int i = 0; i < n-1; i++) {
        for (int j = 0; j < n-i-1; j++) {
            if (arr[j].score > arr[j+1].score) {
                // Swap the students
                struct Student temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
}

int main() {
    struct Student students[100];
    int index = 0;

    while (1) {
        char name[50];
        int score;

        // Read name and score
        scanf("%s", name);
        if (name[0] == '#') {
            break;
        }
        scanf("%d", &score);
      
        // Add student to array
        strcpy(students[index].name, name);
        students[index].score = score;
        index++;
    }

    // Sort the students
    bubbleSort(students, index);

    // Output the sorted students
    for (int i = 0; i < index; i++) {
        printf("%s %d\n", students[i].name, students[i].score);
    }

    return 0;
}
